// 安全存储 手机号
// 使用 AES 加密存储（示例）

// 方式一
const crypto = require('crypto')

function encryptPhone(phone, key) {
  const iv = crypto.randomBytes(16)
  const cipher = crypto.createCipheriv('aes-256-gcm', key, iv)
  const encrypted = Buffer.concat([
    cipher.update(phone, 'utf8'),
    cipher.final(),
  ])
  return iv.toString('hex') + ':' + encrypted.toString('hex')
}

function decryptPhone(encrypted, key) {
  const [ivHex, content] = encrypted.split(':')
  const iv = Buffer.from(ivHex, 'hex')
  const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv)
  return Buffer.concat([
    decipher.update(content, 'hex'),
    decipher.final(),
  ]).toString()
}
// 方式二
